#ifndef _Ape_Serialization_SimpleTypesSerialization_h
#define _Ape_Serialization_SimpleTypesSerialization_h

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

namespace Ape {
	namespace Serialization {
#define byte_t unsigned char
	
		struct BytesChunk {
			size_t  Size;
			byte_t* Bytes;
			
			BytesChunk (size_t size);
			~BytesChunk();
		};
		
		template <typename int_t>
		inline BytesChunk* serialize_integral (int_t value) {
			size_t sizeOfType = sizeof (int_t);
			BytesChunk* chunk = new BytesChunk (sizeOfType);
			char* pValue = (char*) & value;
			memcpy (chunk->Bytes, pValue, sizeOfType);
			return chunk;
		}
		
		template <typename int_t>
		inline int_t unserialize_integral (BytesChunk* chunk) {
			size_t sizeOfType = sizeof (int_t);
			int_t value;
			char* pValue = (char*) & value;
			memcpy (pValue, chunk->Bytes, sizeOfType);
			
			return value;
		}
		
	}
}

#endif // _Ape_Serialization_SimpleTypesSerialization_h
